package com.hc.sss.llz.controller;

import com.hc.sss.common.ResultMap;
import com.hc.sss.pojo.RedEnvelope;
import com.hc.sss.service.RedEnvelopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("re")
public class RedEnvelopeController {

    @Autowired
    RedEnvelopeService redEnvelopeService;

    /*查询所有红包+分页*/
    @RequestMapping("/findRedEnvelopeList")
    @ResponseBody
    public ResultMap<RedEnvelope> findRedEnvelopeList(RedEnvelope redEnvelope, Integer page, Integer limit) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", page);
        paramMap.put("limit", limit);
        paramMap.put("redEnvelope", redEnvelope);
        ResultMap<RedEnvelope> resultMap = redEnvelopeService.findRedEnvelopeList(paramMap);
        return resultMap;
    }

    /*修改红包*/
    @RequestMapping("/updateRedEnvelope")
    @ResponseBody
    public int updateRedEnvelope(RedEnvelope redEnvelope){
        return redEnvelopeService.updateRedEnvelope(redEnvelope);
    }

    /*删除红包*/
    @RequestMapping("/delRedEnvelope")
    @ResponseBody
    public int delRedEnvelope(RedEnvelope redEnvelope){
        redEnvelope.setReStatus(-1);
        return redEnvelopeService.deleteRedEnvelope(redEnvelope);
    }

    //添加红包
    @RequestMapping("/insertRedEnvelope")
    @ResponseBody
    public int insertRedEnvelope(RedEnvelope redEnvelope){
        return redEnvelopeService.insertRedEnvelope(redEnvelope);
    }

    //发送红包
    @RequestMapping("/redEnvelopeSend")
    @ResponseBody
    public int redEnvelopeSend(@RequestParam Integer reId, @RequestParam List<Integer> userId){
        return redEnvelopeService.redEnvelopeSend(reId,userId);
    }
}
